#load packages
library(vcfR)
library(ggplot2)
library(adegenet)
library(SNPfiltR)
library(StAMPP)

#read in vcf as vcfR
#this has been pre-filtered using the command:
#vcftools --vcf populations.snps.vcf --out filt --max-missing .1 --recode --recode-INFO-all
#in order to make sure that the file can be read into Rstudio
vcfR <- read.vcfR("~/Desktop/todi.2022/populations.snps.vcf")
### check the metadata present in your vcf
vcfR

#read in sample info csv
sample.info<-read.csv("~/Desktop/todi.2022/todiramphus.subset.csv")

#make sure sampling file matches vcf
sample.info$id %in% colnames(vcfR@gt)[-1]
colnames(vcfR@gt)[-1] %in% sample.info$id

#if needed, subset sampling file to include only samples in vcf
#sample.info<-sample.info[sample.info$id %in% colnames(vcfR@gt)[-1],]

#reorder sampling file to match order of samples in vcf
sample.info<-sample.info[match(colnames(vcfR@gt)[-1], sample.info$id),]
sample.info$id == colnames(vcfR@gt)[-1]

step 1: Implement quality filters that don’t involve missing data. This is because removing low data samples will alter percentage/quantile based missing data cutoffs, so we wait to implement those until after deciding on our final set of samples for downstream analysis

#hard filter to minimum depth of 5, and minimum genotype quality of 30
vcfR<-hard_filter(vcfR=vcfR, depth = 5, gq = 30)
## 25.19% of genotypes fall below a read depth of 5 and were converted to NA
## 1.6% of genotypes fall below a genotype quality of 30 and were converted to NA

Use this function to filter for allele balance from Puritz SNP filtering tutorial “Allele balance: a number between 0 and 1 representing the ratio of reads showing the reference allele to all reads, considering only reads from individuals called as heterozygous, we expect that the allele balance in our data (for real loci) should be close to 0.5”

#execute allele balance filter
vcfR<-filter_allele_balance(vcfR)
## 9.4% of het genotypes (0.4% of all genotypes) fall outside of 0.25 - 0.75 allele balance ratio and were converted to NA

max depth filter (super high depth loci are likely multiple loci stuck together into a single paralogous locus).

#visualize and pick appropriate max depth cutoff
max_depth(vcfR)
## cutoff is not specified, exploratory visualization will be generated.

## dashed line indicates a mean depth across all SNPs of 53.3

#filter vcf by the max depth cutoff you chose
vcfR<-max_depth(vcfR, maxdepth = 100)
## maxdepth cutoff is specified, filtered vcfR object will be returned
## 16.32% of SNPs were above a mean depth of 100 and were removed from the vcf

#check vcfR to see how many SNPs we have left
vcfR
## ***** Object of Class vcfR *****
## 100 samples
## 347 CHROMs
## 186,091 variants
## Object size: 346.7 Mb
## 83.77 percent missing data
## *****        *****         *****

Step 2: visualize missing data by sample. Check out the visualizations and make decision on which samples to keep for downstream analysis.

#run function to visualize samples
miss<-missing_by_sample(vcfR=vcfR)
## No popmap provided

#histogram of number of SNPs called in each sample at a .5 SNP completeness cutoff
hist(miss$snps.retained[miss$filt == .5], breaks=50)

hist(miss$snps.retained[miss$filt == .5], breaks = 100)

#run function to drop samples above the threshold we want from the vcf
#(going with a very lenient cutoff here, can clean up bad samples down the line if needed)
vcfR<-missing_by_sample(vcfR=vcfR, cutoff = .95)
## 13 samples are above a 0.95 missing data cutoff, and were removed from VCF

#remove invariant sites generated by sample trimming
vcfR<-min_mac(vcfR, min.mac = 1)
## 55.03% of SNPs fell below a minor allele count of 1 and were removed from the VCF

### interrogate potential batch effects between runs

#interrogate batch effects between runs
#make a popmap where pop corresponds to the run the sample was on
batch.map<-sample.info[sample.info$id %in% colnames(vcfR@gt)[-1],c(1,2)]
colnames(batch.map)<-c("id","pop")
batch.map$pop<-as.factor(batch.map$pop)
#
assess_missing_data_pca(vcfR, popmap=batch.map, thresholds = .8, clustering = FALSE)
## cutoff is specified, filtered vcfR object will be returned
## 88.99% of SNPs fell below a completeness cutoff of 0.8 and were removed from the VCF

## [[1]]
##                                PC1         PC2        PC3           PC4
## T_albicilla_22581     -5.619609845 -9.82423507 -5.6631683  2.3753143742
## T_albicilla_22591     -5.717423623 -9.88407832 -5.7154664  2.2913904378
## T_albicilla_22592     -5.725967485 -9.80079329 -5.6737443  2.2766582539
## T_albicilla_22611     -4.177796800 -6.52279651 -3.9054526  1.5877132656
## T_albicilla_85104     -5.708193812 -9.87950482 -5.7359311  2.2453156553
## T_albicilla_85105     -5.661645281 -9.63322160 -5.5898141  2.2380803530
## T_chloris_12584       -2.884902571 -2.61955068  8.1764285 -5.4891731231
## T_chloris_12606       -2.896752624 -2.71588726  7.4748149 -5.6826017864
## T_chloris_13960       -2.716946308 -3.01561267  7.8290716 -8.3586270427
## T_chloris_14446       -2.736092002 -2.67819100  7.7600161 -7.9962968064
## T_chloris_20983       -2.752570486 -2.74826379  8.1036382 -8.0475199804
## T_chloris_22075       -3.006894426 -2.71251205  8.6099593 -5.6564391268
## T_chloris_23253       -2.907370296 -2.80075499  7.5707122 -4.9613340778
## T_chloris_23630       -2.856405177 -3.26997231  6.0917551 -7.8209230467
## T_chloris_23631       -1.461939224 -1.63024908  2.3286337 -3.1018058614
## T_chloris_23632       -2.854743492 -3.12448942  6.1080070 -7.5652742772
## T_chloris_24382       -2.741577175 -2.39812786  7.5527231 -5.2691158023
## T_chloris_24727       -2.730142432 -2.21793363  7.9485378 -4.8469893655
## T_chloris_67535_run1  -1.183571360 -0.65104200  2.1914300 -1.7665941618
## T_colonus_2003089     -3.236104984 -4.24886839 -0.1985283 -1.2274368611
## T_colonus_2003097     -3.252622113 -3.89149866  0.1863762 -1.7455248434
## T_colonus_2004070     -3.347047335 -4.33957576 -0.7487441 -2.0217012839
## T_leucopygius_32019   32.156637096 -7.68813066 -0.5236433 -0.0262991803
## T_leucopygius_32037   23.579958015 -5.75422262 -0.1235100 -0.2374579633
## T_leucopygius_34505   33.394251349 -7.82399769 -0.7054102 -0.0107270786
## T_leucopygius_34508   25.452165860 -6.40525065 -0.1552226 -0.3842523452
## T_leucopygius_DOT6654 31.315823162 -7.58135803 -0.5802596  0.0453003289
## T_sanctus_14877        0.144250151  7.01000299 -1.8642038 -0.2064376433
## T_sanctus_14879       -0.105022825  4.70947603 -1.3541403 -0.4080206729
## T_sanctus_24565       -0.058257699  7.30848609 -2.2670582 -0.0421039302
## T_sanctus_25117        0.275331255  6.68863347 -2.2125103 -0.1415831628
## T_sanctus_33267        0.269760832  7.37325536 -2.0721071 -0.0805246535
## T_sanctus_34636        0.257242492  7.86456970 -2.0315766 -0.6460816853
## T_sanctus_34659       -0.001213983  5.38260853 -1.5678394  0.3210876173
## T_sanctus_35549        0.143420240  6.49109106 -1.5351844 -0.1935377864
## T_sanctus_72545        0.166613468  6.95411287 -2.0090657 -0.0345705931
## T_sanctus_7567         0.209542062  7.69085141 -1.6149440 -0.1383699437
## T_sanctus_76296       -0.439995574  2.80075239 -0.5693844 -0.0009532665
## T_sanctus_B29435       0.021065569  6.52533731 -2.8007788 -0.5141668348
## T_sanctus_B32637       0.369714208  5.73534094 -1.5789716 -0.2771985148
## T_sanctus_B33280       0.414484926  7.25632583 -2.7907777 -0.4252982667
## T_sanctus_B34636       0.332471701  7.94210474 -2.1278755 -0.3392297193
## T_sanctus_B34659       0.660989994  7.99482034 -2.7835523  0.3155432926
## T_sanctus_B34946       0.195439801  7.27462921 -2.2758726 -0.3893582838
## T_sanctus_B43266       0.372644203  6.81233830 -2.2627966  0.1003798172
## T_sanctus_B50292       0.545072524  7.84750287 -2.3215220  0.1300588197
## T_sanctus_B50543       0.536775932  7.32920111 -2.5935509 -0.2584869904
## T_sanctus_B51072       0.273104652  7.37796029 -2.6418314  0.1314908067
## T_sanctus_B52989       0.164156664  3.91121780 -0.9070095 -0.3531468615
## T_sanctus_B53055       0.239746477  5.46171490 -1.6976754  0.1237263016
## T_sanctus_B53068       0.409551444  6.67313187 -1.7470300 -0.4709559068
## T_sanctus_B54673       0.145915084  7.31614939 -2.1007063  0.1242138379
## T_sanctus_B57402       0.406664600  6.50264593 -2.2997550  0.1292246397
## T_sanctus_B59372       0.276809468  7.33980547 -2.0514218 -0.0633623618
## T_sanctus_B60180       0.338370604  6.28172415 -2.0701641 -1.1810266008
## T_sanctus_B60181       0.515601356  7.80712980 -2.6216591 -0.3509515877
## T_sanctus_B60182       0.486913169  8.11988494 -2.2452738  0.0097850298
## T_sanctus_B60183       0.006026180  7.74815281 -2.5653264 -0.0683995764
## T_sanctus_B60184       0.372657771  8.48364907 -1.6589288  0.0758657577
## T_saurophagus_18929   -5.563403753 -9.63334822 -6.1244247  1.5574980378
## T_saurophagus_27804   -5.601051937 -9.62802681 -5.7903054  1.6476538340
## T_saurophagus_36179   -5.666060279 -9.95887314 -6.4454691  1.8148574239
## T_saurophagus_36283   -4.299852715 -7.87587918 -4.5328983  0.9515986165
## T_saurophagus_36284   -5.589355434 -9.76792204 -6.3393952  1.8041122463
## T_saurophagus_69666   -3.508363950 -5.66719078 -3.3335593  1.1405430604
## T_sordidus_B33717     -1.456349993  0.13617120 10.6417458  9.3865758073
## T_sordidus_B33718     -1.685771966 -0.03722172 10.5812971  8.9649628491
## T_sordidus_B33719     -1.395525575  0.05947083  9.4973363  8.8314406330
## T_sordidus_B33720     -1.149771876  0.25129289  9.2180778  8.5617732892
## T_sordidus_B44198     -1.529978048 -0.45861039  8.9517891  7.8208246186
## T_sordidus_B44295     -1.735515698 -0.56895009  8.8991997  8.0191337106
## T_sordidus_B44296     -1.476192151 -0.87763038  8.7500529  7.6275179921
## T_sordidus_B51462     -1.558207787 -0.19103853  9.7547024  8.9684620483
## T_tristrami_18953     -4.729052772 -7.66111196 -2.8790853 -0.3772306207
## T_tristrami_27723     -4.066837450 -6.99635502 -2.5383971 -0.2535373319
## T_tristrami_27752     -2.821682559 -5.22588119 -1.5838331 -0.5459367417
## T_tristrami_27792     -3.301542964 -5.21193993 -1.3370356 -0.5087129076
## T_tristrami_27793     -4.266958713 -6.73543498 -2.1798357 -0.2456332747
## T_tristrami_32049     -4.636546122 -7.36322135 -2.4202593 -0.6801370775
## T_tristrami_33253     -4.642341602 -7.36230901 -2.9006873 -0.1149905375
## T_tristrami_33839      0.462467250  7.35308849 -1.9572941  0.7809419349
## T_tristrami_33858      0.173492298  5.04864744 -1.2549830  0.0715561002
## T_tristrami_33864      0.249679458  7.38874575 -1.9840580 -0.7857049504
## T_tristrami_33867      0.535852411  7.42322819 -2.3030836  0.4258100168
## T_tristrami_33895      0.490705756  6.43634224 -1.8794549 -0.4896334902
## T_tristrami_36188     -4.135723647 -6.89745790 -2.6704629 -0.1070496166
## T_tristrami_6704      -4.764473559 -8.13307255 -3.2123944  0.0120145979
##                                PC5 pop     missing
## T_albicilla_22581     -5.872573828   2 0.039509389
## T_albicilla_22591     -6.293191137   2 0.014219038
## T_albicilla_22592     -6.201250149   1 0.023119505
## T_albicilla_22611     -4.144467829   1 0.268425052
## T_albicilla_85104     -5.992700394   1 0.039400847
## T_albicilla_85105     -6.049712586   1 0.040377727
## T_chloris_12584       -1.135361618   1 0.008466298
## T_chloris_12606       -1.113174651   1 0.030283295
## T_chloris_13960       -2.181362549   1 0.024747639
## T_chloris_14446       -2.165722818   1 0.014978834
## T_chloris_20983       -2.316695124   1 0.016824053
## T_chloris_22075       -1.273559728   1 0.013567785
## T_chloris_23253       -1.115072761   1 0.059806795
## T_chloris_23630       -2.419407590   2 0.107891024
## T_chloris_23631       -0.974303777   1 0.543037013
## T_chloris_23632       -2.519934401   1 0.099641810
## T_chloris_24382       -1.449010952   1 0.072180614
## T_chloris_24727       -1.148200218   1 0.114620645
## T_chloris_67535_run1  -0.146057111   1 0.595897102
## T_colonus_2003089      4.292569904   1 0.109844785
## T_colonus_2003097      4.046463687   1 0.091066971
## T_colonus_2004070      4.700492860   1 0.110713123
## T_leucopygius_32019   -0.139754801   3 0.110278954
## T_leucopygius_32037    0.225811589   3 0.355367416
## T_leucopygius_34505   -0.356473578   3 0.094757408
## T_leucopygius_34508    0.153828882   3 0.297297297
## T_leucopygius_DOT6654 -0.306048834   3 0.146206447
## T_sanctus_14877       -0.460931802   1 0.036578747
## T_sanctus_14879       -0.231898620   1 0.320850971
## T_sanctus_24565        0.052571997   1 0.012807989
## T_sanctus_25117        0.011576109   1 0.073374579
## T_sanctus_33267       -0.302170056   1 0.022468251
## T_sanctus_34636       -0.637225767   1 0.019646152
## T_sanctus_34659        0.302937983   1 0.232280473
## T_sanctus_35549        0.139231811   1 0.073917291
## T_sanctus_72545        0.055748452   1 0.037664170
## T_sanctus_7567         0.043248927   1 0.022902420
## T_sanctus_76296       -0.099629939   1 0.477043308
## T_sanctus_B29435      -0.006436275   2 0.089764463
## T_sanctus_B32637      -0.102098696   2 0.268967763
## T_sanctus_B33280      -0.162668608   2 0.146206447
## T_sanctus_B34636      -0.579462141   2 0.029957669
## T_sanctus_B34659       0.255683907   2 0.040377727
## T_sanctus_B34946      -0.366631440   2 0.040377727
## T_sanctus_B43266       0.057328968   2 0.091392597
## T_sanctus_B50292      -0.253276174   2 0.079561489
## T_sanctus_B50543       0.118707875   2 0.018126560
## T_sanctus_B51072       0.171413815   2 0.013350700
## T_sanctus_B52989      -0.347880579   2 0.425811354
## T_sanctus_B53055      -0.444358656   2 0.243460328
## T_sanctus_B53068      -0.616644834   2 0.057418865
## T_sanctus_B54673      -0.558788075   2 0.037772712
## T_sanctus_B57402      -0.776929754   2 0.179963096
## T_sanctus_B59372       0.007531646   2 0.008574840
## T_sanctus_B60180       0.030839294   2 0.248453273
## T_sanctus_B60181      -0.042389851   2 0.080104201
## T_sanctus_B60182       0.155040704   2 0.010745685
## T_sanctus_B60183      -0.545305872   2 0.018235103
## T_sanctus_B60184       0.153601918   2 0.011722566
## T_saurophagus_18929   -2.878916587   1 0.018235103
## T_saurophagus_27804   -3.343678450   1 0.010420059
## T_saurophagus_36179   -3.286922258   2 0.013133616
## T_saurophagus_36283   -2.322460564   2 0.248019103
## T_saurophagus_36284   -3.213173648   2 0.006295452
## T_saurophagus_69666   -1.787985720   1 0.365244763
## T_sordidus_B33717      0.340856841   2 0.015630088
## T_sordidus_B33718      0.150296348   1 0.014653207
## T_sordidus_B33719      0.094791196   2 0.128839683
## T_sordidus_B33720      0.140565504   2 0.139910995
## T_sordidus_B44198     -0.020180007   2 0.124497992
## T_sordidus_B44295      0.259868209   1 0.058287203
## T_sordidus_B44296      0.081474251   2 0.155975252
## T_sordidus_B51462     -0.112640792   2 0.072723326
## T_tristrami_18953      7.978119685   1 0.023770759
## T_tristrami_27723      6.104783708   2 0.133507001
## T_tristrami_27752      4.858770144   2 0.378704005
## T_tristrami_27792      5.631588635   1 0.233474438
## T_tristrami_27793      7.055494182   1 0.052534462
## T_tristrami_32049      8.148850759   1 0.026701400
## T_tristrami_33253      8.646526214   1 0.007597959
## T_tristrami_33839     -0.379724289   2 0.018994899
## T_tristrami_33858     -0.396295021   2 0.275805926
## T_tristrami_33864     -0.170461442   2 0.015087377
## T_tristrami_33867     -0.129652402   2 0.017692391
## T_tristrami_33895      0.316046865   2 0.172690763
## T_tristrami_36188      7.399634991   2 0.123738196
## T_tristrami_6704       7.708556895   1 0.033431021
#samples are clustering as species and within species by missing data, no indication of batch effects here

Step 3: Set the arbitrary missing data cutoff

We can visualize the effect that typical missing data cutoffs will have on both the number of SNPs retained and the total missing data in our entire dataset. We want to choose a cutoff that minimizes the overall missing data in the dataset, while maximizing the total number of loci retained.

#visualize missing data by SNP and the effect of various cutoffs on the missingness of each sample
missing_by_snp(vcfR)
## cutoff is not specified, exploratory visualizations will be generated
## Picking joint bandwidth of 0.0708

##    filt missingness snps.retained
## 1  0.30  0.37867104         38368
## 2  0.50  0.26724679         25480
## 3  0.60  0.21218939         19571
## 4  0.65  0.18834898         17054
## 5  0.70  0.16464662         14578
## 6  0.75  0.13461192         11480
## 7  0.80  0.11262072          9213
## 8  0.85  0.08904051          6762
## 9  0.90  0.05966766          3747
## 10 0.95  0.03138883          1304
## 11 1.00  0.00000000            66
#still need to target specific samples with too much missing data even at high filtering thresholds, for removal
#rerun missing by sample
miss<-missing_by_sample(vcfR=vcfR)
## No popmap provided

#show me the samples with the most missing data at a 85% completeness threshold
filt<-miss[miss$filt == .8,]
filt[order(filt$snps.retained),]
##                     indiv filt snps.retained
## 280  T_chloris_67535_run1  0.8          3723
## 276       T_chloris_23631  0.8          4210
## 299       T_sanctus_76296  0.8          4818
## 310      T_sanctus_B52989  0.8          5290
## 337     T_tristrami_27752  0.8          5724
## 326   T_saurophagus_69666  0.8          5848
## 285   T_leucopygius_32037  0.8          5939
## 290       T_sanctus_14879  0.8          6257
## 287   T_leucopygius_34508  0.8          6474
## 343     T_tristrami_33858  0.8          6672
## 301      T_sanctus_B32637  0.8          6735
## 265     T_albicilla_22611  0.8          6740
## 316      T_sanctus_B60180  0.8          6924
## 324   T_saurophagus_36283  0.8          6928
## 311      T_sanctus_B53055  0.8          6970
## 338     T_tristrami_27792  0.8          7062
## 295       T_sanctus_34659  0.8          7073
## 314      T_sanctus_B57402  0.8          7555
## 346     T_tristrami_33895  0.8          7622
## 333     T_sordidus_B44296  0.8          7776
## 288 T_leucopygius_DOT6654  0.8          7866
## 302      T_sanctus_B33280  0.8          7866
## 330     T_sordidus_B33720  0.8          7924
## 336     T_tristrami_27723  0.8          7983
## 329     T_sordidus_B33719  0.8          8026
## 331     T_sordidus_B44198  0.8          8066
## 347     T_tristrami_36188  0.8          8073
## 279       T_chloris_24727  0.8          8157
## 283     T_colonus_2004070  0.8          8193
## 284   T_leucopygius_32019  0.8          8197
## 281     T_colonus_2003089  0.8          8201
## 275       T_chloris_23630  0.8          8219
## 277       T_chloris_23632  0.8          8295
## 286   T_leucopygius_34505  0.8          8340
## 306      T_sanctus_B43266  0.8          8371
## 282     T_colonus_2003097  0.8          8374
## 300      T_sanctus_B29435  0.8          8386
## 317      T_sanctus_B60181  0.8          8475
## 307      T_sanctus_B50292  0.8          8480
## 296       T_sanctus_35549  0.8          8532
## 292       T_sanctus_25117  0.8          8537
## 334     T_sordidus_B51462  0.8          8543
## 278       T_chloris_24382  0.8          8548
## 274       T_chloris_23253  0.8          8662
## 332     T_sordidus_B44295  0.8          8676
## 312      T_sanctus_B53068  0.8          8684
## 339     T_tristrami_27793  0.8          8729
## 267     T_albicilla_85105  0.8          8841
## 304      T_sanctus_B34659  0.8          8841
## 305      T_sanctus_B34946  0.8          8841
## 262     T_albicilla_22581  0.8          8849
## 266     T_albicilla_85104  0.8          8850
## 313      T_sanctus_B54673  0.8          8865
## 297       T_sanctus_72545  0.8          8866
## 289       T_sanctus_14877  0.8          8876
## 348      T_tristrami_6704  0.8          8905
## 269       T_chloris_12606  0.8          8934
## 303      T_sanctus_B34636  0.8          8937
## 340     T_tristrami_32049  0.8          8967
## 270       T_chloris_13960  0.8          8985
## 335     T_tristrami_18953  0.8          8994
## 264     T_albicilla_22592  0.8          9000
## 298        T_sanctus_7567  0.8          9002
## 293       T_sanctus_33267  0.8          9006
## 294       T_sanctus_34636  0.8          9032
## 342     T_tristrami_33839  0.8          9038
## 319      T_sanctus_B60183  0.8          9045
## 321   T_saurophagus_18929  0.8          9045
## 308      T_sanctus_B50543  0.8          9046
## 345     T_tristrami_33867  0.8          9050
## 272       T_chloris_20983  0.8          9058
## 327     T_sordidus_B33717  0.8          9069
## 344     T_tristrami_33864  0.8          9074
## 271       T_chloris_14446  0.8          9075
## 328     T_sordidus_B33718  0.8          9078
## 263     T_albicilla_22591  0.8          9082
## 273       T_chloris_22075  0.8          9088
## 309      T_sanctus_B51072  0.8          9090
## 323   T_saurophagus_36179  0.8          9092
## 291       T_sanctus_24565  0.8          9095
## 320      T_sanctus_B60184  0.8          9105
## 318      T_sanctus_B60182  0.8          9114
## 322   T_saurophagus_27804  0.8          9117
## 315      T_sanctus_B59372  0.8          9134
## 268       T_chloris_12584  0.8          9135
## 341     T_tristrami_33253  0.8          9143
## 325   T_saurophagus_36284  0.8          9155
#drop the three continuing outlier samples at a 85% SNP completeness threshold
vcfR<- vcfR[,colnames(vcfR@gt) != "T_chloris_67535_run1" &
             colnames(vcfR@gt) != "T_chloris_23631" &
             colnames(vcfR@gt) != "T_sanctus_76296" &
             colnames(vcfR@gt) != "T_sanctus_B52989"]
#remove invariant SNPs
vcfR<-min_mac(vcfR, min.mac = 1)
## 3.47% of SNPs fell below a minor allele count of 1 and were removed from the VCF

vcfR
## ***** Object of Class vcfR *****
## 83 samples
## 194 CHROMs
## 80,776 variants
## Object size: 214.5 Mb
## 64.46 percent missing data
## *****        *****         *****
#re-visualize missing data by SNP and the effect of various cutoffs on the missingness of each sample
missing_by_snp(vcfR)
## cutoff is not specified, exploratory visualizations will be generated
## Picking joint bandwidth of 0.0683

##    filt missingness snps.retained
## 1  0.30  0.37361219         39441
## 2  0.50  0.25707739         26163
## 3  0.60  0.20532767         20689
## 4  0.65  0.18083119         18133
## 5  0.70  0.14973052         14917
## 6  0.75  0.12481566         12377
## 7  0.80  0.10038540          9910
## 8  0.85  0.07571551          7430
## 9  0.90  0.05149154          5011
## 10 0.95  0.02791287          2636
## 11 1.00  0.00000000           300
#all samples look decent at high thresholds

#make popmap
popmap<-sample.info[sample.info$id %in% colnames(vcfR@gt)[-1],c(1,5)]
colnames(popmap)<-c("id","pop")
popmap$pop<-as.factor(popmap$pop)

#assess missing data effects on clustering
assess_missing_data_pca(vcfR = vcfR, popmap = popmap, thresholds = c(.75,.8,.85), clustering = FALSE)
## cutoff is specified, filtered vcfR object will be returned
## 84.68% of SNPs fell below a completeness cutoff of 0.75 and were removed from the VCF

## cutoff is specified, filtered vcfR object will be returned

## 87.73% of SNPs fell below a completeness cutoff of 0.8 and were removed from the VCF

## cutoff is specified, filtered vcfR object will be returned

## 90.8% of SNPs fell below a completeness cutoff of 0.85 and were removed from the VCF

## [[1]]
##                               PC1         PC2         PC3         PC4
## T_albicilla_22581       7.0121667 -11.0542908 -7.04969813  1.76177557
## T_albicilla_22591       7.3296157 -11.4351352 -7.32346820  1.85847022
## T_albicilla_22592       7.2348018 -11.1700446 -7.24323460  1.85246241
## T_albicilla_22611       5.1386906  -7.1723689 -4.81785836  1.40353643
## T_albicilla_85104       7.1254748 -10.8769395 -7.20980916  1.93330690
## T_albicilla_85105       7.0452229 -10.6757005 -6.98833498  1.92866178
## T_chloris_12584         4.1996443  -3.2481522 10.33987648 -6.38570656
## T_chloris_12606         3.9406958  -2.9281397  9.39164631 -6.66917818
## T_chloris_13960         3.8584281  -3.2334374 10.10877582 -9.42290305
## T_chloris_14446         3.9190017  -3.0409967 10.26880994 -9.12175722
## T_chloris_20983         3.9943601  -3.1548780 10.61499048 -9.12263727
## T_chloris_22075         4.1667635  -2.9617041 11.11217144 -6.65032619
## T_chloris_23253         3.7881375  -2.6992906  8.79958377 -5.56697016
## T_chloris_23630         3.5725535  -3.4315625  7.65171376 -7.74165518
## T_chloris_23632         3.9034378  -3.1958691  7.80865230 -7.72389003
## T_chloris_24382         3.6258084  -2.4778154  9.20699003 -6.30261635
## T_chloris_24727         3.6099238  -2.0625425  9.23297379 -5.41808640
## T_colonus_2003089       4.2576035  -4.2716136  0.05452408 -1.50333321
## T_colonus_2003097       4.1274821  -3.8523564  0.52533832 -1.76127104
## T_colonus_2004070       4.3872330  -4.4181938 -0.49481431 -2.10147416
## T_leucopygius_32019   -36.0984446 -10.9610646 -0.16264739 -0.34301185
## T_leucopygius_32037   -26.9886590  -8.0719500  0.21679712 -0.10753881
## T_leucopygius_34505   -37.6777214 -11.3757775 -0.22900681 -0.13009757
## T_leucopygius_34508   -28.8525385  -8.8433370  0.22757448 -0.47258652
## T_leucopygius_DOT6654 -35.2178405 -10.6458975 -0.24783081 -0.18743472
## T_sanctus_14877        -1.0189915   8.7750105 -2.31136481 -0.48397043
## T_sanctus_14879        -0.3966857   5.7087024 -1.37514512 -0.42178233
## T_sanctus_24565        -0.7403862   9.0319056 -2.73269358 -0.09900194
## T_sanctus_25117        -1.0037876   8.1538841 -2.32106467 -0.30825914
## T_sanctus_33267        -1.2352819   9.2364888 -2.39759861 -0.24571407
## T_sanctus_34636        -1.0026027   9.4172542 -2.51520808 -0.73129240
## T_sanctus_34659        -0.6532669   6.2523593 -1.51104271  0.26325900
## T_sanctus_35549        -0.7134587   7.6064671 -1.52748212 -0.44948412
## T_sanctus_72545        -0.7439014   8.4283878 -2.09711871 -0.30490331
## T_sanctus_7567         -0.9733815   9.1112542 -1.77959678 -0.34560827
## T_sanctus_B29435       -0.8748905   7.6783686 -2.71475844 -0.67520500
## T_sanctus_B32637       -0.9278681   6.1592727 -1.81590305 -0.32818595
## T_sanctus_B33280       -1.1366560   7.8913742 -2.70104518 -0.73747100
## T_sanctus_B34636       -1.0679826   9.2741254 -2.54336162 -0.43019430
## T_sanctus_B34659       -1.5171704   9.0087426 -3.28036161  0.02924152
## T_sanctus_B34946       -0.9303180   8.4874878 -2.30099439 -0.49666269
## T_sanctus_B43266       -0.9285970   7.5837405 -2.00258384 -0.16938556
## T_sanctus_B50292       -1.2446582   8.7264615 -2.58426202  0.01128691
## T_sanctus_B50543       -1.3810840   9.0736433 -3.09119936 -0.35788985
## T_sanctus_B51072       -1.1513129   8.9686316 -2.98727441  0.02972107
## T_sanctus_B53055       -0.6879519   5.7790918 -1.54661531  0.10431938
## T_sanctus_B53068       -1.0929738   7.9003911 -1.81822131 -0.53725489
## T_sanctus_B54673       -1.0327342   8.7533743 -2.37175274 -0.02151578
## T_sanctus_B57402       -1.0173929   6.9349038 -2.52868292 -0.09178685
## T_sanctus_B59372       -1.0430501   9.0809128 -2.50910701 -0.02139196
## T_sanctus_B60180       -0.9963268   6.8584212 -2.05663365 -1.28588228
## T_sanctus_B60181       -1.3582288   8.9361777 -2.54439385 -0.53112919
## T_sanctus_B60182       -1.2534007   9.6475167 -2.59761202 -0.19065148
## T_sanctus_B60183       -1.0176890   9.5823300 -2.93417989 -0.11884465
## T_sanctus_B60184       -1.3294372  10.1209940 -2.07810375 -0.05955343
## T_saurophagus_18929     7.2281086 -10.9098179 -7.46109373  1.00409292
## T_saurophagus_27804     7.2556589 -10.9250839 -7.10555919  1.15234095
## T_saurophagus_36179     7.2500499 -11.1966130 -7.78817532  1.28236450
## T_saurophagus_36283     4.9210242  -8.2600709 -5.08204344  0.38219205
## T_saurophagus_36284     7.3408384 -11.2655985 -7.75299084  1.24807181
## T_saurophagus_69666     4.5859862  -6.1436285 -3.95032627  0.95323619
## T_sordidus_B33717       2.4308976  -0.3574010 12.21204937 11.40416418
## T_sordidus_B33718       2.7135812  -0.5410739 11.76947083 11.04834654
## T_sordidus_B33719       2.0437040  -0.3728679 10.20051581 10.30936110
## T_sordidus_B33720       1.7606294  -0.2313845  9.57257426 10.10200976
## T_sordidus_B44198       2.1966048  -0.9117969  9.49920107  9.48311449
## T_sordidus_B44295       2.6154588  -1.0239365  9.57471312  9.64473976
## T_sordidus_B44296       2.0884795  -1.3383391  9.48026708  9.11609663
## T_sordidus_B51462       2.2855812  -0.5669639 10.19118574 10.87931271
## T_tristrami_18953       6.2914294  -8.4422248 -3.54263685 -0.32449540
## T_tristrami_27723       4.8349788  -7.1311052 -2.84121438 -0.44677527
## T_tristrami_27752       3.1781011  -5.1635096 -1.61197733 -0.60472586
## T_tristrami_27792       4.1754542  -5.4045458 -1.84282897 -0.52937686
## T_tristrami_27793       5.6018004  -7.2675229 -2.94909420 -0.17416183
## T_tristrami_32049       6.0872566  -8.1367206 -3.37177596 -0.56680938
## T_tristrami_33253       6.1795486  -8.2606669 -3.60049751 -0.14718975
## T_tristrami_33839      -1.2678297   8.8791525 -2.13036469  0.79961757
## T_tristrami_33858      -0.6110964   5.2662522 -1.42391134 -0.18530633
## T_tristrami_33864      -0.9786316   8.8575360 -2.59612022 -0.61507484
## T_tristrami_33867      -1.2432742   8.9285815 -2.79760735  0.60314561
## T_tristrami_33895      -1.1125745   7.0053857 -1.92210576 -0.36154634
## T_tristrami_36188       5.0516680  -7.3169378 -3.09902760 -0.32309989
## T_tristrami_6704        6.1661925  -8.6777152 -3.84898012 -0.13419089
##                                PC5         PC6          PC7          PC8
## T_albicilla_22581     -6.974209456  0.47557915  5.271767670 -4.871267198
## T_albicilla_22591     -7.439804837  0.33965724  5.275563711 -4.991129105
## T_albicilla_22592     -7.091362737  0.31384699  5.030229138 -4.790033906
## T_albicilla_22611     -4.507965860  0.34011826  3.836307094 -3.222900332
## T_albicilla_85104     -6.828484701  0.62837153  4.853771794 -3.993637062
## T_albicilla_85105     -6.880966999  0.54913464  4.877002823 -3.778448218
## T_chloris_12584       -1.615337405 -8.07473884  1.742439228  1.681234477
## T_chloris_12606       -1.559791878 -7.71762766  2.003367110  1.013225629
## T_chloris_13960       -2.140280850  8.24626850 -3.239752836 -2.434596008
## T_chloris_14446       -1.955476960  8.60966752 -3.490966758 -2.547877069
## T_chloris_20983       -2.249805511  8.21193975 -3.583149381 -2.746264759
## T_chloris_22075       -1.678574136 -7.85856998  1.427676722  1.424257741
## T_chloris_23253       -1.487966433 -7.07217561  1.712592440  1.358009482
## T_chloris_23630       -1.936352177  6.17126435 -2.927860012 -2.313578037
## T_chloris_23632       -2.193284591  6.09974144 -2.264857009 -2.034992481
## T_chloris_24382       -2.074950426 -8.26108158  2.131810539  1.661871518
## T_chloris_24727       -1.659291094 -8.07928652  1.809237216  1.366337465
## T_colonus_2003089      5.644245608  5.88093840  9.360861438  8.649461717
## T_colonus_2003097      5.382461580  5.85761416  9.059623626  8.699491313
## T_colonus_2004070      6.095712775  5.70210614  9.525439380  8.547828183
## T_leucopygius_32019   -0.122400996 -0.14787477  0.179067085 -0.027288792
## T_leucopygius_32037    0.218098969  0.36492252 -0.187055213 -0.492034495
## T_leucopygius_34505   -0.309476678 -0.21939178  0.278031292  0.303086909
## T_leucopygius_34508    0.294710206 -0.03820655 -0.311011248 -0.140900878
## T_leucopygius_DOT6654 -0.217097674 -0.14226868  0.114394503  0.288071568
## T_sanctus_14877       -0.504188466 -0.62042847  0.149599136 -0.120953266
## T_sanctus_14879       -0.261663345 -0.13068101 -0.376560186  0.314916148
## T_sanctus_24565       -0.046458884  0.07459296 -0.281177388  0.103281213
## T_sanctus_25117       -0.002890203  0.01178232 -0.390045502  0.401925453
## T_sanctus_33267       -0.449984703 -0.38712998 -0.001925164 -0.321173617
## T_sanctus_34636       -0.480214097 -0.06010353  0.670669123 -0.576807852
## T_sanctus_34659        0.065160647  0.35485713 -0.715376112 -0.082507059
## T_sanctus_35549        0.079846206  0.22428826 -0.463304646 -0.312843625
## T_sanctus_72545        0.198963983  0.31124328 -0.521408925 -0.502720948
## T_sanctus_7567        -0.313223738 -0.23040274 -0.162973137 -0.320062047
## T_sanctus_B29435       0.026845311  0.55153187  0.344218529  0.843419413
## T_sanctus_B32637      -0.448504196 -0.52886141 -0.009859801  0.019552303
## T_sanctus_B33280      -0.281910044 -0.16511347 -0.449527650 -0.611732864
## T_sanctus_B34636      -0.407504212  0.03613173  0.788453981 -0.405503728
## T_sanctus_B34659      -0.065463466 -0.01163201 -0.807757277  0.013726820
## T_sanctus_B34946      -0.351404874 -0.03018599  0.046067499 -0.379861082
## T_sanctus_B43266       0.048706787 -0.15337162 -0.497923736  0.444855022
## T_sanctus_B50292      -0.571741680  0.50055781 -0.636341333 -0.350799192
## T_sanctus_B50543      -0.053117871 -0.21142943 -0.458386035  0.042903893
## T_sanctus_B51072       0.041941388  0.05266011  0.587328964 -0.372740395
## T_sanctus_B53055      -0.492803373 -0.44759631  0.142000379 -0.135359458
## T_sanctus_B53068      -0.452906231  0.34557907 -1.030172279 -0.517170089
## T_sanctus_B54673      -0.599647058  0.28185079 -0.192729306  0.010769192
## T_sanctus_B57402      -0.861435022  0.06433312 -0.029523341 -0.456524451
## T_sanctus_B59372       0.338621678 -0.26223951 -1.445992904 -0.395736385
## T_sanctus_B60180      -0.175871262 -0.16534749  0.835797384  0.419357242
## T_sanctus_B60181      -0.404478268 -0.67001884  0.849140181 -0.384971942
## T_sanctus_B60182      -0.082777941 -0.37211787  0.288978300  0.132516336
## T_sanctus_B60183      -0.951129338 -0.56044299  0.712501069 -0.194828457
## T_sanctus_B60184       0.019217515 -0.36326401 -0.019615731  0.280199941
## T_saurophagus_18929   -3.458978224 -0.48579947 -6.713872965  6.720748592
## T_saurophagus_27804   -3.682462406 -0.48858985 -5.937245064  5.970456240
## T_saurophagus_36179   -3.777696352 -0.53209163 -6.814187280  6.757433169
## T_saurophagus_36283   -2.309036752 -0.41652129 -4.643458226  4.118826703
## T_saurophagus_36284   -3.898775567 -0.57689696 -6.639273584  6.613264973
## T_saurophagus_69666   -2.011394923 -0.17370221 -3.862742977  3.725787977
## T_sordidus_B33717      0.019705336  0.78409681 -0.610854570  0.176995063
## T_sordidus_B33718     -0.202323938  1.09856953 -0.990441284  0.111789521
## T_sordidus_B33719      0.022487243  0.55930818 -0.817762566  0.154216026
## T_sordidus_B33720     -0.216260445 -0.13739699 -0.590534924  0.214911034
## T_sordidus_B44198      0.065996838  1.21834939  0.158539810 -0.369897638
## T_sordidus_B44295      0.176167071  0.93200915  0.186181967 -0.395637432
## T_sordidus_B44296     -0.173238884  1.07649976 -0.148579866 -0.351299188
## T_sordidus_B51462     -0.391114399  0.32077596 -0.529004889 -0.160475490
## T_tristrami_18953      9.226168771 -1.53288090 -1.826591899 -3.232734336
## T_tristrami_27723      6.647924648 -1.29326237 -1.139394022 -2.649409239
## T_tristrami_27752      4.872910759 -1.04908717 -0.688799762 -1.363225975
## T_tristrami_27792      5.992636466 -0.44711550  0.352831469 -2.046957139
## T_tristrami_27793      7.790159661 -1.63664456 -0.875010298 -3.318660763
## T_tristrami_32049      9.649967824 -1.23907559 -1.552762539 -3.606579525
## T_tristrami_33253     10.327562319 -1.55535025 -1.952473389 -3.443176301
## T_tristrami_33839     -0.500343812  0.10630646 -1.066312892 -0.503730306
## T_tristrami_33858     -0.524608591  0.14730857  0.012545070 -0.009221095
## T_tristrami_33864     -0.212115185 -0.72595869 -0.160067984 -0.652726757
## T_tristrami_33867     -0.027162111  0.38570494 -0.185308282  0.503151098
## T_tristrami_33895      0.238406919  0.64124395  0.589103524  0.543462318
## T_tristrami_36188      8.031363953 -1.41995987 -1.399678685 -3.140151718
## T_tristrami_6704       9.051720799 -1.17882974 -1.563528337 -3.560213996
##                                 PC9        PC10         pop    missing
## T_albicilla_22581     -0.2003713363  0.29997485   albicilla 0.05865719
## T_albicilla_22591     -0.1640565007  0.28140272   albicilla 0.01769411
## T_albicilla_22592     -0.2807100996  0.27766683   albicilla 0.03805446
## T_albicilla_22611      0.2106154151  0.26241912   albicilla 0.29878000
## T_albicilla_85104     -0.2067801883  0.19515839   albicilla 0.05849560
## T_albicilla_85105     -0.1103777375  0.15845476   albicilla 0.06011150
## T_chloris_12584        0.2780921007  0.19694020     chloris 0.01413913
## T_chloris_12606        0.0451716103  0.28969596     chloris 0.04371011
## T_chloris_13960       -0.3546547301 -0.89845140     chloris 0.04257898
## T_chloris_14446       -0.4545858200 -0.39590621     chloris 0.02205704
## T_chloris_20983       -0.3069659936 -0.57081054     chloris 0.02238022
## T_chloris_22075       -0.0455745598  0.48731295     chloris 0.01591662
## T_chloris_23253        0.1216404714  0.59307337     chloris 0.11012362
## T_chloris_23630        0.2024514286 -0.07964462     chloris 0.17451725
## T_chloris_23632        0.3682890249  0.27665226     chloris 0.13565484
## T_chloris_24382       -0.0006162337  0.49643673     chloris 0.10527592
## T_chloris_24727        0.3190902678  0.33982414     chloris 0.15035954
## T_colonus_2003089     -0.2508650684  0.46740898     colonus 0.13840187
## T_colonus_2003097      0.1517822161  0.57708436     colonus 0.13775551
## T_colonus_2004070      0.0799190312  0.32125531     colonus 0.14009857
## T_leucopygius_32019    0.0395610553  0.07604338 leucopygius 0.13226145
## T_leucopygius_32037   -0.0399074733 -0.29057141 leucopygius 0.36818292
## T_leucopygius_34505   -0.0804982134  0.26214961 leucopygius 0.11222429
## T_leucopygius_34508   -0.3892514531 -0.85743491 leucopygius 0.31671649
## T_leucopygius_DOT6654  0.5944954740  0.20798953 leucopygius 0.17168942
## T_sanctus_14877       -4.8834503659 -6.23255390     sanctus 0.05582936
## T_sanctus_14879       -1.8693697155 -1.91893545     sanctus 0.34442918
## T_sanctus_24565        1.0616152540  1.40023305     sanctus 0.02197625
## T_sanctus_25117        1.1358630712  0.81916206     sanctus 0.09267189
## T_sanctus_33267        0.2785348386  1.53282452     sanctus 0.03175244
## T_sanctus_34636       14.2671174865 -6.00670556     sanctus 0.03506504
## T_sanctus_34659       -0.9113232729  4.58440724     sanctus 0.26638119
## T_sanctus_35549        0.8871769683  1.16737732     sanctus 0.11133554
## T_sanctus_72545       -0.5512637421  1.31217989     sanctus 0.05534459
## T_sanctus_7567        -0.9343093908  3.10327462     sanctus 0.03902400
## T_sanctus_B29435      -0.2363037405  0.91096815     sanctus 0.14696615
## T_sanctus_B32637      -0.7253746413  1.75669068     sanctus 0.34539872
## T_sanctus_B33280      -0.4354222409  3.48235453     sanctus 0.22178234
## T_sanctus_B34636      14.0743092953 -5.65615374     sanctus 0.05833401
## T_sanctus_B34659      -0.9399070112  6.73862493     sanctus 0.07360427
## T_sanctus_B34946       1.2649495237  1.02179730     sanctus 0.07045326
## T_sanctus_B43266      -0.8204736989  1.49868467     sanctus 0.14664297
## T_sanctus_B50292      -0.5616866900  4.27131006     sanctus 0.12902965
## T_sanctus_B50543       0.0344275234  2.12697711     sanctus 0.02092591
## T_sanctus_B51072      -0.7494517090  1.63222564     sanctus 0.02221863
## T_sanctus_B53055       0.6574821479  0.84106042     sanctus 0.31607013
## T_sanctus_B53068       0.7893978559  2.43561026     sanctus 0.08855135
## T_sanctus_B54673      -0.0739832809  2.04908235     sanctus 0.07408904
## T_sanctus_B57402      -0.2483205042  1.57331901     sanctus 0.25143411
## T_sanctus_B59372       0.1568147308  2.01866721     sanctus 0.01413913
## T_sanctus_B60180      -2.7281457659 -4.23101791     sanctus 0.32705825
## T_sanctus_B60181      -4.5021158621 -6.05988781     sanctus 0.13169589
## T_sanctus_B60182      -3.4365229504 -7.20617141     sanctus 0.01583582
## T_sanctus_B60183      -5.4242838983 -8.34937473     sanctus 0.02763190
## T_sanctus_B60184      -5.3788043730 -6.92986257     sanctus 0.01672457
## T_saurophagus_18929    0.2034109133 -0.35435197 saurophagus 0.03716571
## T_saurophagus_27804    0.3172567005 -0.52659399 saurophagus 0.02431930
## T_saurophagus_36179    0.2658898175 -0.50946618 saurophagus 0.02682395
## T_saurophagus_36283    0.0815378888 -0.40752972 saurophagus 0.32180658
## T_saurophagus_36284    0.2323698839 -0.52562086 saurophagus 0.01123051
## T_saurophagus_69666    0.0977589240 -0.25785324 saurophagus 0.37852468
## T_sordidus_B33717     -0.0542296397 -0.43418304    sordidus 0.02730872
## T_sordidus_B33718      0.1721330922  0.14322501    sordidus 0.02286499
## T_sordidus_B33719      0.6542731642 -0.52912886    sordidus 0.19229215
## T_sordidus_B33720      0.4548270865 -0.64597532    sordidus 0.20255312
## T_sordidus_B44198      0.1101022682  0.14736387    sordidus 0.18712127
## T_sordidus_B44295     -0.5240656865  0.22372566    sordidus 0.09412620
## T_sordidus_B44296     -0.2630655306 -0.11568020    sordidus 0.22008564
## T_sordidus_B51462     -0.1771055517 -0.13174051    sordidus 0.11691040
## T_tristrami_18953      0.0467837275 -0.23211872   tristrami 0.04080149
## T_tristrami_27723      0.1189185718 -0.17116028   tristrami 0.19544316
## T_tristrami_27752      0.2674676879 -0.08680509   tristrami 0.45810778
## T_tristrami_27792     -0.3654840987 -0.50074421   tristrami 0.29708330
## T_tristrami_27793     -0.3091475000 -0.15545798   tristrami 0.09008645
## T_tristrami_32049      0.5083792115  0.22514162   tristrami 0.03967036
## T_tristrami_33253     -0.0808743448 -0.16771567   tristrami 0.01203846
## T_tristrami_33839      1.0237599502  1.78936200   tristrami 0.03417629
## T_tristrami_33858     -0.8905985696  0.93067931   tristrami 0.35283187
## T_tristrami_33864     -0.6428311767  2.68466676   tristrami 0.02092591
## T_tristrami_33867     -0.2194380943  2.51237180   tristrami 0.02965177
## T_tristrami_33895      0.3739009477  1.32236686   tristrami 0.24715198
## T_tristrami_36188      0.2228433099 -0.45530682   tristrami 0.17847621
## T_tristrami_6704      -0.3478414825 -0.43176253   tristrami 0.06188899
## 
## [[2]]
##                                 PC1           PC2          PC3         PC4
## T_albicilla_22581       6.092947696 -10.072082827 -5.955672604  2.38848790
## T_albicilla_22591       6.220846982 -10.164918610 -5.995341116  2.30394461
## T_albicilla_22592       6.205398580 -10.066810857 -5.907150214  2.28911882
## T_albicilla_22611       4.440754567  -6.492130635 -3.963400516  1.54476154
## T_albicilla_85104       6.172358440 -10.066497872 -5.915553310  2.30328175
## T_albicilla_85105       6.109579562  -9.795865850 -5.831407772  2.33362104
## T_chloris_12584         3.230539703  -2.695106240  8.625426954 -5.94335385
## T_chloris_12606         3.142689903  -2.545845234  7.859712981 -6.27507146
## T_chloris_13960         3.035768301  -3.031292928  8.194600204 -8.92521330
## T_chloris_14446         3.061330574  -2.685705526  8.296823078 -8.59335736
## T_chloris_20983         3.098933715  -2.718770393  8.725212630 -8.66144046
## T_chloris_22075         3.291518911  -2.621846442  9.103738068 -6.17076720
## T_chloris_23253         3.082581783  -2.546130203  7.700124510 -5.38955177
## T_chloris_23630         3.101882443  -3.232118976  6.317223794 -7.95647414
## T_chloris_23632         3.069000344  -3.031121716  6.314523671 -7.79416245
## T_chloris_24382         2.901761931  -2.204895201  7.782230794 -5.83967492
## T_chloris_24727         2.921185491  -2.033089433  8.001002891 -5.27277329
## T_colonus_2003089       3.456613287  -4.144649375 -0.233417105 -1.37180859
## T_colonus_2003097       3.462898459  -3.804279239  0.185419338 -1.76115422
## T_colonus_2004070       3.597268806  -4.419759990 -0.741049927 -2.04163632
## T_leucopygius_32019   -32.967578551  -8.677047697 -0.423972137 -0.08124960
## T_leucopygius_32037   -23.892628848  -6.359954685  0.006619215 -0.22829750
## T_leucopygius_34505   -34.275036734  -8.877413289 -0.574109545 -0.02606897
## T_leucopygius_34508   -26.050806383  -7.220040359 -0.102190186 -0.43485895
## T_leucopygius_DOT6654 -32.050581053  -8.492931925 -0.478400373 -0.05869077
## T_sanctus_14877        -0.369307461   7.433510144 -1.981294403 -0.21007325
## T_sanctus_14879        -0.001792175   4.863881249 -1.294683592 -0.37802636
## T_sanctus_24565        -0.119730890   7.760456735 -2.472513231 -0.05545290
## T_sanctus_25117        -0.525087704   7.210789913 -2.232622386 -0.13326772
## T_sanctus_33267        -0.560090453   7.926831761 -2.185049308 -0.09418472
## T_sanctus_34636        -0.455528476   8.300712876 -2.035397363 -0.79828856
## T_sanctus_34659        -0.085473957   5.539518329 -1.496671401  0.27774286
## T_sanctus_35549        -0.349372104   6.830507783 -1.474377748 -0.26433323
## T_sanctus_72545        -0.334070083   7.225620782 -1.928113392 -0.13126942
## T_sanctus_7567         -0.413790790   8.017743239 -1.635983210 -0.23995738
## T_sanctus_B29435       -0.272230971   6.870347595 -2.792770429 -0.42362772
## T_sanctus_B32637       -0.582569627   6.063104091 -1.788794347 -0.27244556
## T_sanctus_B33280       -0.720847551   7.707582185 -2.903556447 -0.29837177
## T_sanctus_B34636       -0.518050241   8.314336391 -2.171000719 -0.44066968
## T_sanctus_B34659       -0.873178875   8.365504803 -2.985199271  0.33168370
## T_sanctus_B34946       -0.371387960   7.433289384 -2.388533633 -0.18485581
## T_sanctus_B43266       -0.587459750   7.127769015 -2.249127304  0.01933968
## T_sanctus_B50292       -0.735782256   8.104274163 -2.323412713  0.32488903
## T_sanctus_B50543       -0.745892033   7.784955042 -2.682691025 -0.37450259
## T_sanctus_B51072       -0.486771124   7.792610873 -2.711690390  0.12628164
## T_sanctus_B53055       -0.365481495   5.609552765 -1.737803804  0.13685896
## T_sanctus_B53068       -0.599289708   7.020652304 -1.882806275 -0.47386086
## T_sanctus_B54673       -0.425965671   7.820207754 -2.223981319  0.03582019
## T_sanctus_B57402       -0.581305750   6.711352582 -2.373977292  0.16956998
## T_sanctus_B59372       -0.508711070   7.745063631 -2.018251380 -0.16938789
## T_sanctus_B60180       -0.592156473   6.571230042 -2.096035658 -1.22488965
## T_sanctus_B60181       -0.749659967   8.191265116 -2.576617125 -0.29578770
## T_sanctus_B60182       -0.699830922   8.483392786 -2.379503234  0.02888877
## T_sanctus_B60183       -0.267590419   8.228949949 -2.661716968 -0.06147706
## T_sanctus_B60184       -0.616697779   8.842604362 -1.719872193 -0.03534484
## T_saurophagus_18929     6.046950695  -9.860352523 -6.337639804  1.39873909
## T_saurophagus_27804     6.084444783  -9.917360528 -6.023092278  1.53425991
## T_saurophagus_36179     6.153311020 -10.166078589 -6.655676298  1.64627183
## T_saurophagus_36283     4.653765564  -8.066550258 -4.764132979  0.87080513
## T_saurophagus_36284     6.108329355 -10.044485206 -6.578631808  1.64862526
## T_saurophagus_69666     3.778596643  -5.689075096 -3.389871922  1.07990258
## T_sordidus_B33717       1.710584209   0.007376488 11.301956529  9.62029290
## T_sordidus_B33718       1.960771478  -0.186633023 11.195432854  9.26310280
## T_sordidus_B33719       1.591110360  -0.075682701 10.146295302  8.89320812
## T_sordidus_B33720       1.359780933   0.115049937  9.758664811  8.72742632
## T_sordidus_B44198       1.764694112  -0.567649821  9.553593498  7.97497298
## T_sordidus_B44295       1.961721835  -0.666418941  9.354633313  8.16554984
## T_sordidus_B44296       1.697766866  -0.954688141  9.306748401  7.76920150
## T_sordidus_B51462       1.825043052  -0.311243345 10.341448464  9.26415049
## T_tristrami_18953       5.165352673  -7.886499732 -2.999345747 -0.36478029
## T_tristrami_27723       4.410387948  -7.099961957 -2.635239677 -0.35657664
## T_tristrami_27752       3.046458866  -5.304486556 -1.646404905 -0.59487589
## T_tristrami_27792       3.482730954  -5.210578704 -1.528196339 -0.55670766
## T_tristrami_27793       4.614354064  -6.925410336 -2.368579825 -0.29720527
## T_tristrami_32049       5.037225767  -7.584817214 -2.526045769 -0.67842502
## T_tristrami_33253       5.032052514  -7.639138251 -3.021346776 -0.26461246
## T_tristrami_33839      -0.743700965   7.854736856 -1.970162095  0.80487127
## T_tristrami_33858      -0.333295744   5.245240109 -1.436376007  0.06680060
## T_tristrami_33864      -0.539337525   7.875852136 -2.317173630 -0.73369557
## T_tristrami_33867      -0.773127314   7.907570238 -2.453380649  0.46959678
## T_tristrami_33895      -0.678606957   6.722501307 -1.790068637 -0.34217194
## T_tristrami_36188       4.467389684  -7.120125556 -2.806638175 -0.14495414
## T_tristrami_6704        5.171120959  -8.348402734 -3.297715612 -0.09238323
##                                PC5         PC6          PC7           PC8
## T_albicilla_22581     -6.298258306  0.62767667  5.766140254  3.1522279346
## T_albicilla_22591     -6.661436001  0.52057293  5.720592539  3.0148091100
## T_albicilla_22592     -6.530661360  0.51032944  5.387559140  2.7968230699
## T_albicilla_22611     -4.161097444  0.49808556  3.848194835  1.7914694594
## T_albicilla_85104     -6.418281615  0.73243799  5.212044240  2.2921457041
## T_albicilla_85105     -6.367335627  0.63730359  5.177882620  2.1030001686
## T_chloris_12584       -1.346260145 -7.44350309  1.429590297 -1.8471395455
## T_chloris_12606       -1.372209202 -7.01624354  2.016043671 -1.3414731624
## T_chloris_13960       -2.291606717  7.11573717 -2.545291915  2.9115131827
## T_chloris_14446       -2.238240611  7.48317644 -2.439468281  2.8539150708
## T_chloris_20983       -2.413355742  6.91642292 -2.567757845  3.0885926620
## T_chloris_22075       -1.395107149 -6.92663668  1.184460449 -1.4387477513
## T_chloris_23253       -1.280449810 -6.36062656  1.377723238 -1.5211220400
## T_chloris_23630       -2.105815436  5.64335992 -2.444800087  2.5127372704
## T_chloris_23632       -2.335990895  5.38756884 -1.988529781  2.2928868305
## T_chloris_24382       -1.672960267 -7.46823986  1.647887946 -1.9049276810
## T_chloris_24727       -1.369090078 -7.32494118  1.760088241 -1.8398583967
## T_colonus_2003089      4.556137144  5.65844907  5.446864540 -9.8905595009
## T_colonus_2003097      4.376180023  5.67363585  5.208693125 -9.8786542790
## T_colonus_2004070      4.940357997  5.44277126  5.523089740 -9.8266482126
## T_leucopygius_32019   -0.208979823 -0.19608752  0.152323299  0.0237044028
## T_leucopygius_32037    0.191822272  0.31759262 -0.022057316  0.4342300366
## T_leucopygius_34505   -0.340673326 -0.23389526  0.156378911 -0.2538666268
## T_leucopygius_34508    0.130415173 -0.01620895 -0.121464077  0.0971132603
## T_leucopygius_DOT6654 -0.340733171 -0.09156867 -0.024493439 -0.1456255208
## T_sanctus_14877       -0.396073291 -0.45865761  0.494609458  0.0046867983
## T_sanctus_14879       -0.384883093 -0.02661100 -0.078237746 -0.2640684134
## T_sanctus_24565        0.079146832 -0.44774355 -0.451492043  0.1746052842
## T_sanctus_25117        0.044740188 -0.11856254 -0.517228503 -0.3446927897
## T_sanctus_33267       -0.341914436 -0.39864399  0.283247174  0.1389867818
## T_sanctus_34636       -0.668575504 -0.33533261 -0.024207452  0.5754392783
## T_sanctus_34659        0.223679726  0.30296760 -0.582525565  0.1556119538
## T_sanctus_35549        0.174653357  0.26327997 -0.189689627  0.0839633301
## T_sanctus_72545        0.088661056  0.24662732 -0.095743233  0.3489033770
## T_sanctus_7567        -0.094328440 -0.29175827  0.183806498  0.0887991455
## T_sanctus_B29435       0.072382414  0.46654923 -0.008587424 -0.5024098800
## T_sanctus_B32637      -0.219119065 -0.46086263 -0.003509084  0.0319698111
## T_sanctus_B33280      -0.157095801 -0.21437787 -0.332960078  0.6449317490
## T_sanctus_B34636      -0.586933315 -0.20701998 -0.000329519  0.5172166964
## T_sanctus_B34659       0.131030234 -0.20565258 -0.723215127  0.1459195176
## T_sanctus_B34946      -0.430753989 -0.25362266 -0.102314511  0.5957843893
## T_sanctus_B43266       0.151248600 -0.31561906 -0.108762223 -0.2422098124
## T_sanctus_B50292      -0.279941189  0.26987841 -0.447423484  0.5901838003
## T_sanctus_B50543       0.131909887  0.01359181 -0.325014885 -0.0888047842
## T_sanctus_B51072       0.149518824  0.22766399  0.714767168  0.1242419951
## T_sanctus_B53055      -0.438741474 -0.45650230 -0.026417158  0.3900021051
## T_sanctus_B53068      -0.482478460  0.22148353 -0.646424462  0.4023573925
## T_sanctus_B54673      -0.666217247  0.27873101 -0.281325787 -0.0552076031
## T_sanctus_B57402      -0.751204434  0.01373909 -0.236577881  0.5704562142
## T_sanctus_B59372       0.081713228 -0.31080489 -0.932551951  0.5477837722
## T_sanctus_B60180      -0.047354638  0.07012784  0.793931136 -0.4222468465
## T_sanctus_B60181      -0.209883057 -0.31835588  1.203855505  0.3992346960
## T_sanctus_B60182       0.091657079 -0.05905250  0.450250745  0.0009571224
## T_sanctus_B60183      -0.722978879 -0.21903947  0.846841083 -0.1934094065
## T_sanctus_B60184       0.165353303 -0.28421931  0.320185940 -0.2418419519
## T_saurophagus_18929   -2.954752435 -1.03336483 -7.482485044 -3.9973953511
## T_saurophagus_27804   -3.429289348 -1.00428040 -6.415912920 -3.5290916896
## T_saurophagus_36179   -3.355925085 -1.13790366 -7.540127253 -3.9140481492
## T_saurophagus_36283   -2.362801891 -0.84872019 -5.540059078 -2.6751985654
## T_saurophagus_36284   -3.332368002 -1.12638149 -7.342750750 -3.9642260666
## T_saurophagus_69666   -1.834807231 -0.59304316 -4.163051588 -2.0857800849
## T_sordidus_B33717      0.308450293  0.90065654 -0.467984537  0.0437621241
## T_sordidus_B33718      0.081083467  1.00244511 -0.989100600  0.1593810135
## T_sordidus_B33719      0.235714149  0.71952140 -0.866781567 -0.0333681844
## T_sordidus_B33720      0.101320778 -0.04270858 -0.835610426 -0.0940463399
## T_sordidus_B44198      0.007538713  1.17926063  0.197368280  0.2364324374
## T_sordidus_B44295      0.321157083  0.87501393  0.088792257  0.3402984846
## T_sordidus_B44296     -0.020835406  1.17018778 -0.106203915  0.3222657509
## T_sordidus_B51462     -0.171040247  0.27776856 -0.448898214  0.2738691827
## T_tristrami_18953      8.354048085 -1.08669113 -0.350613223  3.2701609773
## T_tristrami_27723      6.192153869 -1.06603337 -0.073821133  2.5628683585
## T_tristrami_27752      4.817998136 -1.04677148 -0.130292010  1.3850350699
## T_tristrami_27792      5.633309713 -0.33031051  0.817809323  1.6711763103
## T_tristrami_27793      7.199773895 -1.37875999  0.207708852  3.0424744034
## T_tristrami_32049      8.409930972 -0.67057013 -0.573285812  3.3109044403
## T_tristrami_33253      9.136560018 -1.15187021 -0.552318447  3.3272553021
## T_tristrami_33839     -0.420893960  0.09765055 -1.048826045  0.6470038549
## T_tristrami_33858     -0.317156551  0.28541825 -0.069643615  0.1839284256
## T_tristrami_33864     -0.270017088 -0.63525205  0.133391690  0.5797574521
## T_tristrami_33867     -0.025638437  0.45603646 -0.310440815 -0.6545402410
## T_tristrami_33895      0.351581509  0.71497501  0.233066440 -0.4798081973
## T_tristrami_36188      7.555056623 -1.04837374 -0.180029405  3.0483033291
## T_tristrami_6704       8.036260078 -0.55726935 -0.228551752  3.3689367841
##                                 PC9         PC10         pop     missing
## T_albicilla_22581      -0.052900091  0.322741756   albicilla 0.039455096
## T_albicilla_22591      -0.084307455  0.366213644   albicilla 0.014631685
## T_albicilla_22592      -0.015858408  0.304133631   albicilla 0.026841574
## T_albicilla_22611      -0.394697282  0.240497899   albicilla 0.284157417
## T_albicilla_85104       0.001673160  0.251239927   albicilla 0.048234107
## T_albicilla_85105      -0.106227942  0.330398468   albicilla 0.047830474
## T_chloris_12584        -0.223552668  0.269403805     chloris 0.009788093
## T_chloris_12606         0.111351513  0.210269782     chloris 0.037336024
## T_chloris_13960         0.354942817 -0.565684390     chloris 0.029061554
## T_chloris_14446         0.377229416 -0.041821008     chloris 0.015842583
## T_chloris_20983         0.352591311 -0.339831921     chloris 0.018567104
## T_chloris_22075         0.139492276  0.513491279     chloris 0.015035318
## T_chloris_23253         0.106396714  0.475215290     chloris 0.076387487
## T_chloris_23630         0.037286129  0.001475619     chloris 0.118668012
## T_chloris_23632        -0.131027033  0.104445175     chloris 0.118970737
## T_chloris_24382         0.017087988  0.360150382     chloris 0.089404642
## T_chloris_24727        -0.091584083  0.211530394     chloris 0.134207871
## T_colonus_2003089      -0.466510729  0.422280140     colonus 0.122603431
## T_colonus_2003097      -0.637862462  0.371211622     colonus 0.105449041
## T_colonus_2004070      -0.565934853  0.322423118     colonus 0.124924319
## T_leucopygius_32019    -0.173963753  0.081663736 leucopygius 0.117356206
## T_leucopygius_32037     0.334326700 -0.471519637 leucopygius 0.369323915
## T_leucopygius_34505    -0.003790306  0.318310947 leucopygius 0.101715439
## T_leucopygius_34508     0.577603668 -0.648716308 leucopygius 0.306659939
## T_leucopygius_DOT6654  -0.688769854  0.183155475 leucopygius 0.157013118
## T_sanctus_14877         4.017362746 -5.461522584     sanctus 0.043995964
## T_sanctus_14879         1.204709714 -1.284191667     sanctus 0.339051463
## T_sanctus_24565        -1.024012997  1.094588148     sanctus 0.015136226
## T_sanctus_25117        -1.076606255  0.510553040     sanctus 0.082038345
## T_sanctus_33267        -0.476017154  1.650413223     sanctus 0.026135217
## T_sanctus_34636       -12.589934563 -5.274328850     sanctus 0.025428860
## T_sanctus_34659         1.154880365  3.794758780     sanctus 0.248839556
## T_sanctus_35549        -1.025439805  1.216998130     sanctus 0.087991927
## T_sanctus_72545         0.441631446  0.970165121     sanctus 0.045408678
## T_sanctus_7567          0.271301414  2.579273716     sanctus 0.028456105
## T_sanctus_B29435        0.021439598  0.433001189     sanctus 0.097578204
## T_sanctus_B32637        0.662512715  1.723735002     sanctus 0.281130172
## T_sanctus_B33280        0.134988621  3.618571520     sanctus 0.153077699
## T_sanctus_B34636      -12.482978590 -5.147555782     sanctus 0.033905146
## T_sanctus_B34659        1.480150901  5.577428634     sanctus 0.042381433
## T_sanctus_B34946       -1.039375900  0.618823166     sanctus 0.047023209
## T_sanctus_B43266        0.455076212  0.799674015     sanctus 0.097578204
## T_sanctus_B50292        1.175622795  3.951464961     sanctus 0.083854692
## T_sanctus_B50543        0.086830128  1.958278059     sanctus 0.017860747
## T_sanctus_B51072        0.580018587  1.286692316     sanctus 0.014328961
## T_sanctus_B53055       -0.957151286  0.633320743     sanctus 0.254187689
## T_sanctus_B53068       -0.570247254  1.427888709     sanctus 0.059334006
## T_sanctus_B54673        0.231623813  1.794731702     sanctus 0.042482341
## T_sanctus_B57402        0.640068170  1.448941103     sanctus 0.190413724
## T_sanctus_B59372       -0.373745803  2.623081494     sanctus 0.008476287
## T_sanctus_B60180        3.215068103 -3.989047376     sanctus 0.255297679
## T_sanctus_B60181        4.269993134 -5.747485791     sanctus 0.085973764
## T_sanctus_B60182        3.501039271 -6.634343165     sanctus 0.010797175
## T_sanctus_B60183        4.603419044 -7.329570051     sanctus 0.019172553
## T_sanctus_B60184        4.420949020 -5.946555363     sanctus 0.011503532
## T_saurophagus_18929     0.134946906 -0.488372022 saurophagus 0.024520686
## T_saurophagus_27804     0.094509531 -0.510629865 saurophagus 0.015237134
## T_saurophagus_36179     0.092665120 -0.528368321 saurophagus 0.015539859
## T_saurophagus_36283     0.217080279 -0.389168951 saurophagus 0.251463169
## T_saurophagus_36284     0.137792886 -0.565139745 saurophagus 0.007870838
## T_saurophagus_69666     0.093721876 -0.180880885 saurophagus 0.381432896
## T_sordidus_B33717      -0.004682335 -0.331531463    sordidus 0.017860747
## T_sordidus_B33718      -0.215913545  0.065241856    sordidus 0.016548940
## T_sordidus_B33719      -0.730550289 -0.365917932    sordidus 0.135216953
## T_sordidus_B33720      -0.562784815 -0.555068407    sordidus 0.146922301
## T_sordidus_B44198       0.038921420  0.177124027    sordidus 0.131886983
## T_sordidus_B44295       0.742813349 -0.027004728    sordidus 0.069929364
## T_sordidus_B44296       0.315676735 -0.075786509    sordidus 0.161755802
## T_sordidus_B51462       0.143493047 -0.045086290    sordidus 0.076892028
## T_tristrami_18953      -0.003983793 -0.054350021   tristrami 0.030272452
## T_tristrami_27723       0.095332438 -0.270971110   tristrami 0.135721493
## T_tristrami_27752      -0.346754072 -0.119697034   tristrami 0.388092836
## T_tristrami_27792       0.428510103 -0.586606602   tristrami 0.256710394
## T_tristrami_27793       0.361864847 -0.340767726   tristrami 0.061150353
## T_tristrami_32049      -0.442321360  0.227506853   tristrami 0.030070636
## T_tristrami_33253       0.013433850  0.006098795   tristrami 0.009081736
## T_tristrami_33839      -0.813052247  1.707067864   tristrami 0.022300706
## T_tristrami_33858       0.727865546  0.713864412   tristrami 0.285771948
## T_tristrami_33864       0.301343335  2.279301422   tristrami 0.015237134
## T_tristrami_33867      -0.043567689  3.015457477   tristrami 0.017860747
## T_tristrami_33895      -0.160271635  1.211543462   tristrami 0.178607467
## T_tristrami_36188      -0.441053456 -0.197016113   tristrami 0.127951564
## T_tristrami_6704        0.098793004 -0.261303412   tristrami 0.041775984
## 
## [[3]]
##                               PC1         PC2         PC3          PC4
## T_albicilla_22581       5.6452390 -8.41239840 -5.26281901  2.035329274
## T_albicilla_22591       5.6832063 -8.33728683 -5.24203958  1.964060555
## T_albicilla_22592       5.6831131 -8.26086973 -5.08093255  1.834000232
## T_albicilla_22611       4.0539320 -5.46903998 -3.46666627  1.380183607
## T_albicilla_85104       5.6950096 -8.38543637 -5.22059915  1.841820295
## T_albicilla_85105       5.6514486 -8.13088805 -5.07694529  1.731437790
## T_chloris_12584         2.6846536 -2.43618609  7.15034669 -5.056849236
## T_chloris_12606         2.7878221 -2.42676963  6.62837541 -5.554308113
## T_chloris_13960         2.5905652 -2.78419132  6.87121164 -8.078667197
## T_chloris_14446         2.5362635 -2.44885951  6.66128381 -7.180251996
## T_chloris_20983         2.5663595 -2.48004348  7.02702548 -7.488778660
## T_chloris_22075         2.7413150 -2.41049636  7.67349655 -5.387969736
## T_chloris_23253         2.6999684 -2.61643005  6.81559769 -4.756401022
## T_chloris_23630         2.7380806 -3.10671890  5.66416156 -7.542775187
## T_chloris_23632         2.6605392 -2.83783507  5.20594517 -6.765861129
## T_chloris_24382         2.5032655 -2.11360717  6.70102646 -4.950189873
## T_chloris_24727         2.5081048 -2.09734408  6.97947307 -4.640618985
## T_colonus_2003089       3.1443937 -3.67345991 -0.17831535 -1.166091537
## T_colonus_2003097       3.0834069 -3.50141322  0.02831708 -1.443139403
## T_colonus_2004070       3.1339628 -3.78798452 -0.87987061 -1.616569058
## T_leucopygius_32019   -28.5543271 -8.19034114 -0.57740988  0.005705525
## T_leucopygius_32037   -20.2695617 -5.96639578 -0.13225300 -0.167211416
## T_leucopygius_34505   -29.5935790 -8.42680422 -0.78681096  0.074590332
## T_leucopygius_34508   -22.6930469 -6.91718582 -0.15226248 -0.124307186
## T_leucopygius_DOT6654 -27.7871292 -8.11335368 -0.59868985  0.072632644
## T_sanctus_14877        -0.5578654  6.23810445 -1.44576024 -0.604079601
## T_sanctus_14879        -0.2962484  4.35558041 -1.09121575 -0.474037780
## T_sanctus_24565        -0.3500885  6.74262764 -1.88967712  0.180470651
## T_sanctus_25117        -0.7149583  6.19497469 -2.12784709 -0.007793604
## T_sanctus_33267        -0.6522212  6.59063409 -1.50670937 -0.228983896
## T_sanctus_34636        -0.6336239  7.19028431 -1.72124869 -0.581490192
## T_sanctus_34659        -0.2843195  4.97957835 -1.29233089  0.155135766
## T_sanctus_35549        -0.4853389  6.05294816 -1.39148974 -0.244293553
## T_sanctus_72545        -0.5153050  6.45251560 -1.60174978  0.124121799
## T_sanctus_7567         -0.6667380  7.08406971 -1.32357662  0.066595532
## T_sanctus_B29435       -0.3964496  6.17258882 -2.51088713 -0.340629738
## T_sanctus_B32637       -0.6536034  5.60635033 -1.39293920 -0.311172006
## T_sanctus_B33280       -0.7486419  6.84296250 -2.40397402 -0.257011168
## T_sanctus_B34636       -0.6984801  7.33580858 -1.88758344 -0.343291544
## T_sanctus_B34659       -1.0137437  7.25110359 -2.33732993  0.112295065
## T_sanctus_B34946       -0.5974342  6.66159533 -1.86046646 -0.261562502
## T_sanctus_B43266       -0.7086985  6.48204652 -2.18159280  0.053863580
## T_sanctus_B50292       -0.9373012  7.13993890 -1.95658421  0.098770471
## T_sanctus_B50543       -0.9138289  6.56875252 -2.15878677 -0.196626903
## T_sanctus_B51072       -0.6883753  6.71811696 -2.45402180  0.213218337
## T_sanctus_B53055       -0.4120105  5.23177019 -1.47034402  0.169967841
## T_sanctus_B53068       -0.7475792  6.17845897 -1.54354742 -0.430702482
## T_sanctus_B54673       -0.5289031  6.73179896 -1.79177139  0.368406671
## T_sanctus_B57402       -0.5652764  6.32228754 -2.08732841  0.104600591
## T_sanctus_B59372       -0.5864496  6.59083791 -1.92560723 -0.110646991
## T_sanctus_B60180       -0.6196309  6.06787861 -1.78001059 -1.000836161
## T_sanctus_B60181       -0.8673624  7.17337090 -2.18235958 -0.347033485
## T_sanctus_B60182       -0.8048558  7.27912615 -1.88117555  0.133661905
## T_sanctus_B60183       -0.3994268  7.22178366 -2.32744705 -0.322094373
## T_sanctus_B60184       -0.7719923  7.54493985 -1.14582570 -0.066485887
## T_saurophagus_18929     5.5132942 -8.04261261 -5.63566251  1.492370799
## T_saurophagus_27804     5.5214192 -8.09568247 -5.26950425  1.539493225
## T_saurophagus_36179     5.6151762 -8.38941474 -5.96067220  1.688784914
## T_saurophagus_36283     4.6658259 -7.16752488 -4.64332181  1.223193116
## T_saurophagus_36284     5.4693665 -8.15390171 -5.77216977  1.661716649
## T_saurophagus_69666     3.3525662 -4.69335973 -2.77738586  0.852616743
## T_sordidus_B33717       1.5761060 -0.13870149  9.70225414  7.948231139
## T_sordidus_B33718       1.6850676 -0.14989923  9.51437039  7.488878763
## T_sordidus_B33719       1.4483052 -0.09149056  8.95774046  7.693513421
## T_sordidus_B33720       1.2605462 -0.07077542  8.89658074  7.621189804
## T_sordidus_B44198       1.5419871 -0.32152071  8.57288555  7.102565118
## T_sordidus_B44295       1.6163416 -0.64330257  8.05555711  6.960627102
## T_sordidus_B44296       1.4596427 -0.68341290  8.38375556  6.934516010
## T_sordidus_B51462       1.6637220 -0.41529467  9.16440935  7.640017509
## T_tristrami_18953       4.7172294 -6.91514875 -2.58663475 -0.326577371
## T_tristrami_27723       4.1717161 -6.45193956 -2.43340836 -0.128146007
## T_tristrami_27752       3.1451754 -4.78831908 -1.56984250 -0.353897001
## T_tristrami_27792       3.3021500 -4.83500889 -1.19515277 -0.546426632
## T_tristrami_27793       4.2613683 -6.08006682 -1.86041957 -0.025182308
## T_tristrami_32049       4.5929769 -6.60603734 -2.16839134 -0.429173135
## T_tristrami_33253       4.5779882 -6.54607787 -2.53277078 -0.073025990
## T_tristrami_33839      -0.9543847  6.85923067 -1.68578019  0.481560667
## T_tristrami_33858      -0.3119779  4.70850068 -0.95433080  0.121307620
## T_tristrami_33864      -0.6757799  6.70611009 -1.67828205 -0.860612589
## T_tristrami_33867      -0.8177934  6.82717865 -1.60988412  0.248672051
## T_tristrami_33895      -0.7243216  6.15084225 -1.63893544 -0.579365561
## T_tristrami_36188       4.3312600 -6.37494009 -2.54459633 -0.009552161
## T_tristrami_6704        4.9187719 -7.26892518 -2.80986655 -0.039402760
##                                PC5          PC6          PC7          PC8
## T_albicilla_22581     -5.187871133 -1.252012984  5.868196792  1.172802662
## T_albicilla_22591     -5.475395276 -1.128759865  5.793743674  1.154487096
## T_albicilla_22592     -5.410654039 -1.136945397  5.544712352  0.992730260
## T_albicilla_22611     -3.436596619 -1.076745470  4.247722523  0.816650132
## T_albicilla_85104     -5.225230015 -1.138642082  4.962736135  0.564182901
## T_albicilla_85105     -5.143589157 -0.988940167  4.814554622  0.420048209
## T_chloris_12584       -1.073910441  6.301226302  1.381556673 -1.918244501
## T_chloris_12606       -0.919165979  5.583663708  1.904823594 -1.890576504
## T_chloris_13960       -1.989115710 -5.698881885 -1.928914277  2.987328330
## T_chloris_14446       -2.056426791 -6.011526064 -1.913209523  2.960184204
## T_chloris_20983       -2.088036289 -5.478183926 -1.906589669  3.169079048
## T_chloris_22075       -1.050603902  6.088493935  1.513835445 -1.830661999
## T_chloris_23253       -1.071593976  5.112560223  1.286828795 -1.643986041
## T_chloris_23630       -2.550228654 -4.885167773 -2.094963128  3.041897216
## T_chloris_23632       -2.481480546 -4.401558908 -1.717070754  2.644626220
## T_chloris_24382       -1.194326060  6.325748589  1.621516468 -2.087241976
## T_chloris_24727       -0.911347086  6.158017666  1.733724004 -2.038927912
## T_colonus_2003089      4.059206243 -5.472603190  0.991323177 -9.605343901
## T_colonus_2003097      3.569836845 -5.361617031  0.830047833 -9.415367393
## T_colonus_2004070      4.303180097 -5.116517779  1.174000610 -9.503447539
## T_leucopygius_32019   -0.168434108  0.021870150  0.025207383  0.062678297
## T_leucopygius_32037    0.019221328 -0.179073287  0.431639493  0.169718473
## T_leucopygius_34505   -0.114865050  0.223827695 -0.230804917 -0.055377050
## T_leucopygius_34508   -0.160703665  0.204769986  0.162172164 -0.090001484
## T_leucopygius_DOT6654 -0.200379826 -0.010336040 -0.025040845 -0.049239561
## T_sanctus_14877       -0.217208700  0.431333149  0.608908303 -0.395260844
## T_sanctus_14879       -0.304523223 -0.115839209 -0.060370963 -0.495003236
## T_sanctus_24565       -0.040539343  0.247368204 -0.189068286  0.099526651
## T_sanctus_25117       -0.141171496  0.128955346 -0.178322930 -0.088329056
## T_sanctus_33267       -0.183485960  0.125512166 -0.014672092 -0.188564599
## T_sanctus_34636       -0.465430889  0.509877157 -0.004979664 -0.071574696
## T_sanctus_34659        0.067296968 -0.448216740 -0.288492516  0.169088295
## T_sanctus_35549       -0.030866471 -0.082306717 -0.306435535  0.279440505
## T_sanctus_72545       -0.048083257 -0.012863752  0.072042681  0.590280977
## T_sanctus_7567         0.119339420  0.125721170  0.039521461  0.074364431
## T_sanctus_B29435       0.052245331 -0.288802845 -0.204215998 -0.376239933
## T_sanctus_B32637       0.068175440  0.330860039 -0.151456828 -0.195507815
## T_sanctus_B33280      -0.015624120  0.284937345 -0.291046736  0.918589761
## T_sanctus_B34636      -0.420458237  0.352086525 -0.035991582  0.010892006
## T_sanctus_B34659       0.220552451  0.027063610 -0.280865914  0.361299954
## T_sanctus_B34946      -0.190988722  0.419687731  0.009618425  0.454898412
## T_sanctus_B43266       0.067673358  0.215517473 -0.012783980 -0.311374731
## T_sanctus_B50292      -0.162942498 -0.112553991 -0.256012697  0.785284399
## T_sanctus_B50543      -0.004352241 -0.031191841 -0.209473259 -0.208793775
## T_sanctus_B51072       0.065084705 -0.224718304  0.757967590 -0.006269405
## T_sanctus_B53055      -0.405967920  0.532034142  0.418081253  0.511449284
## T_sanctus_B53068      -0.648150939  0.057614147 -0.384774110  0.647672407
## T_sanctus_B54673      -0.683073699 -0.193372469 -0.100939843  0.164717773
## T_sanctus_B57402      -0.579434870 -0.181866570 -0.085951742  0.625164190
## T_sanctus_B59372      -0.011637982  0.419671285 -0.477883906  0.951599263
## T_sanctus_B60180       0.201644708  0.061470490  0.699596042 -0.489558384
## T_sanctus_B60181       0.192273163  0.059571296  1.098574967  0.020020999
## T_sanctus_B60182       0.547881247 -0.006171584  0.409798559 -0.219801797
## T_sanctus_B60183      -0.239054192  0.384633679  0.896758369 -0.368345945
## T_sanctus_B60184       0.330240813  0.187713705  0.161062861 -0.604896978
## T_saurophagus_18929   -3.218245686  1.829348602 -6.926869936 -1.443689591
## T_saurophagus_27804   -3.623475782  1.750601397 -5.868828012 -1.399275416
## T_saurophagus_36179   -3.634958370  1.954825669 -6.895045124 -1.422188412
## T_saurophagus_36283   -2.941394644  1.604669391 -5.193523780 -1.109702518
## T_saurophagus_36284   -3.471219475  1.903295845 -6.629480668 -1.395568772
## T_saurophagus_69666   -1.935039667  0.974300899 -3.638063546 -0.326245669
## T_sordidus_B33717      0.071063847 -0.642628401 -0.222962523  0.007924132
## T_sordidus_B33718      0.009184373 -1.004820706 -0.687835214 -0.054461622
## T_sordidus_B33719     -0.236151131 -0.598265195 -0.605673098  0.228194378
## T_sordidus_B33720     -0.051496197 -0.201960926 -0.374413866 -0.149156690
## T_sordidus_B44198     -0.061776521 -0.947790668 -0.065449430  0.492931368
## T_sordidus_B44295      0.030219066 -0.673838885 -0.135114024  0.935811455
## T_sordidus_B44296      0.088415012 -0.959526166 -0.336104241  0.687395274
## T_sordidus_B51462     -0.276133384 -0.339301440 -0.441548472  0.113108000
## T_tristrami_18953      7.314117052  0.718071212  0.269303675  2.628917902
## T_tristrami_27723      5.948277198  0.981196086  0.477412506  2.241717401
## T_tristrami_27752      4.683542112  0.859718835  0.159292595  1.165263271
## T_tristrami_27792      5.317267532  0.121372233  1.017669241  1.311897481
## T_tristrami_27793      6.456514484  1.125004108  0.870682594  2.472781154
## T_tristrami_32049      7.392861892  0.503135391 -0.200569713  2.684833086
## T_tristrami_33253      7.588030614  0.835141394 -0.050682755  2.515580934
## T_tristrami_33839     -0.425729809 -0.091653563 -0.766941631  0.911439538
## T_tristrami_33858     -0.186798363 -0.595010735 -0.179071928  0.373018709
## T_tristrami_33864     -0.144920396  0.537777206  0.416176238  0.373965453
## T_tristrami_33867     -0.047364089 -0.117391202 -0.520720508  0.086795773
## T_tristrami_33895      0.380216834 -0.634635783 -0.183166104 -0.224881707
## T_tristrami_36188      6.602850878  0.704474069  0.455542287  2.846157914
## T_tristrami_6704       7.191239585  0.517500291  0.146044883  2.774671876
##                                PC9         PC10         pop     missing
## T_albicilla_22581      0.218280865  -0.06200242   albicilla 0.019246299
## T_albicilla_22591      0.206500293   0.05967875   albicilla 0.007537012
## T_albicilla_22592      0.227380433   0.05729810   albicilla 0.016016151
## T_albicilla_22611      0.270618918  -0.02441943   albicilla 0.265545087
## T_albicilla_85104      0.157866365   0.04104670   albicilla 0.031493943
## T_albicilla_85105      0.265754851   0.05674464   albicilla 0.030955585
## T_chloris_12584        0.164203769   0.08123257     chloris 0.006729475
## T_chloris_12606       -0.063731663   0.29209332     chloris 0.022745626
## T_chloris_13960       -0.714491994  -0.32828869     chloris 0.019919246
## T_chloris_14446       -0.432151826   0.04357376     chloris 0.011574697
## T_chloris_20983       -0.646826205  -0.21226387     chloris 0.012382234
## T_chloris_22075        0.384291356   0.61233231     chloris 0.011440108
## T_chloris_23253        0.267422646   0.56224343     chloris 0.047240915
## T_chloris_23630        0.067148309  -0.12363291     chloris 0.060430686
## T_chloris_23632        0.237977087  -0.22243591     chloris 0.094481830
## T_chloris_24382        0.538039905   0.36839134     chloris 0.062718708
## T_chloris_24727        0.464376727  -0.02477160     chloris 0.110228802
## T_colonus_2003089      0.708257619   0.32452160     colonus 0.100269179
## T_colonus_2003097      0.701004867  -0.09941303     colonus 0.076312248
## T_colonus_2004070      0.814499693   0.13486173     colonus 0.107133244
## T_leucopygius_32019    0.057600545  -0.07115051 leucopygius 0.106594886
## T_leucopygius_32037   -0.253111050   0.37284323 leucopygius 0.371601615
## T_leucopygius_34505    0.022199862  -0.18129032 leucopygius 0.092328398
## T_leucopygius_34508   -0.659220776   0.04132618 leucopygius 0.300538358
## T_leucopygius_DOT6654  0.533886070  -0.28838475 leucopygius 0.140376851
## T_sanctus_14877       -6.148414644  -1.21455015     sanctus 0.030013459
## T_sanctus_14879       -1.708850136  -0.02916317     sanctus 0.330148048
## T_sanctus_24565        0.922055377   0.48996849     sanctus 0.010497981
## T_sanctus_25117        1.038178741  -0.32254842     sanctus 0.066083445
## T_sanctus_33267        2.009101313   0.29878256     sanctus 0.020053836
## T_sanctus_34636        3.888586601 -10.85882464     sanctus 0.017227456
## T_sanctus_34659        1.535323963   2.25764396     sanctus 0.229609690
## T_sanctus_35549        1.425720384   0.44593167     sanctus 0.066352624
## T_sanctus_72545        0.708625854   0.57667174     sanctus 0.032839838
## T_sanctus_7567         1.129673040   1.61702003     sanctus 0.018438762
## T_sanctus_B29435       0.153078770   0.71669814     sanctus 0.053566622
## T_sanctus_B32637       0.974244529   1.62145839     sanctus 0.200942127
## T_sanctus_B33280       2.404304370   2.34731277     sanctus 0.092193809
## T_sanctus_B34636       3.841384171 -10.81045654     sanctus 0.018169583
## T_sanctus_B34659       2.328706498   3.29425115     sanctus 0.023553163
## T_sanctus_B34946       1.331850785  -0.47942460     sanctus 0.025841184
## T_sanctus_B43266      -0.416035955   1.32928141     sanctus 0.046837147
## T_sanctus_B50292       2.428835014   3.15413651     sanctus 0.049932705
## T_sanctus_B50543       1.301963257   1.17457457     sanctus 0.017092867
## T_sanctus_B51072       0.169705831   1.70365551     sanctus 0.011305518
## T_sanctus_B53055       1.279758235  -0.57994924     sanctus 0.185464334
## T_sanctus_B53068       0.804539212   0.23140818     sanctus 0.037146703
## T_sanctus_B54673       0.392227872   1.13691549     sanctus 0.026110363
## T_sanctus_B57402       0.784842325   1.49756464     sanctus 0.115343203
## T_sanctus_B59372       2.300602522   1.56737742     sanctus 0.006325707
## T_sanctus_B60180      -4.776190890  -0.49712510     sanctus 0.169582773
## T_sanctus_B60181      -6.428820889  -1.14000183     sanctus 0.041857335
## T_sanctus_B60182      -6.472170959  -1.49111266     sanctus 0.008613728
## T_sanctus_B60183      -7.029579520  -1.19923968     sanctus 0.011440108
## T_sanctus_B60184      -5.996487561  -0.85358896     sanctus 0.009017497
## T_saurophagus_18929   -0.474336155  -0.03473073 saurophagus 0.013458950
## T_saurophagus_27804   -0.509792245  -0.11609298 saurophagus 0.007133244
## T_saurophagus_36179   -0.537234555  -0.10821649 saurophagus 0.005921938
## T_saurophagus_36283   -0.542517962  -0.13684638 saurophagus 0.174158816
## T_saurophagus_36284   -0.556998592  -0.06730314 saurophagus 0.002153432
## T_saurophagus_69666   -0.003215092   0.10187968 saurophagus 0.386944818
## T_sordidus_B33717     -0.361236315  -0.29142262    sordidus 0.012920592
## T_sordidus_B33718     -0.153431878  -0.05647432    sordidus 0.014939435
## T_sordidus_B33719     -0.237039393  -0.66568513    sordidus 0.081426649
## T_sordidus_B33720     -0.200962613  -0.64280175    sordidus 0.088425303
## T_sordidus_B44198      0.260746420   0.09649012    sordidus 0.074562584
## T_sordidus_B44295     -0.190650914   0.38323511    sordidus 0.051951548
## T_sordidus_B44296      0.045680569   0.39539206    sordidus 0.096096904
## T_sordidus_B51462      0.047079200  -0.07830341    sordidus 0.036473755
## T_tristrami_18953      0.240052074  -0.17553615   tristrami 0.017631225
## T_tristrami_27723     -0.267470617   0.01763533   tristrami 0.080619112
## T_tristrami_27752     -0.015940875  -0.16979356   tristrami 0.303499327
## T_tristrami_27792     -0.574525468  -0.12805275   tristrami 0.216419919
## T_tristrami_27793     -0.499361958   0.11628532   tristrami 0.041588156
## T_tristrami_32049      0.415561436  -0.33476624   tristrami 0.021130552
## T_tristrami_33253      0.032609399  -0.05234804   tristrami 0.006056528
## T_tristrami_33839      1.514005547   0.61558295   tristrami 0.011574697
## T_tristrami_33858      0.329704623   0.83523258   tristrami 0.204845222
## T_tristrami_33864      1.513544509   1.42010639   tristrami 0.015074024
## T_tristrami_33867      1.910056047   1.47392616   tristrami 0.008882907
## T_tristrami_33895      0.914015181   0.98036321   tristrami 0.114939435
## T_tristrami_36188      0.055514246  -0.43655638   tristrami 0.074831763
## T_tristrami_6704       0.131610608  -0.33600069   tristrami 0.023283984

evaluate the effect of missing data using splitstree

#set two potential cutoffs
vcfRa<-missing_by_snp(vcfR, cutoff = .8)
## cutoff is specified, filtered vcfR object will be returned
## 87.73% of SNPs fell below a completeness cutoff of 0.8 and were removed from the VCF

vcfRb<-missing_by_snp(vcfR, cutoff = .85)
## cutoff is specified, filtered vcfR object will be returned
## 90.8% of SNPs fell below a completeness cutoff of 0.85 and were removed from the VCF

#convert each to genlight
gena<-vcfR2genlight(vcfRa)
genb<-vcfR2genlight(vcfRb)

#output pairwise difference matrix for each to run splitstree
gena@ind.names<-gsub(gena@ind.names, pattern = "T_", replacement = "")
gena@ind.names<-gsub(gena@ind.names, pattern = "_", replacement = "")
gena@ind.names<-gsub(gena@ind.names, pattern = "albicilla", replacement = "alb")
gena@ind.names<-gsub(gena@ind.names, pattern = "chloris", replacement = "chlor")
gena@ind.names<-gsub(gena@ind.names, pattern = "colonus", replacement = "col")
gena@ind.names<-gsub(gena@ind.names, pattern = "sanctus", replacement = "san")
gena@ind.names<-gsub(gena@ind.names, pattern = "saurophagus", replacement = "saur")
gena@ind.names<-gsub(gena@ind.names, pattern = "sordidus", replacement = "sord")
gena@ind.names<-gsub(gena@ind.names, pattern = "tristrami", replacement = "tris")
gena@ind.names<-gsub(gena@ind.names, pattern = "leucopygius", replacement = "leu")
gena@ind.names<-gsub(gena@ind.names, pattern = "DOT", replacement = "D")
gena@ind.names
##  [1] "alb22581"   "alb22591"   "alb22592"   "alb22611"   "alb85104"  
##  [6] "alb85105"   "chlor12584" "chlor12606" "chlor13960" "chlor14446"
## [11] "chlor20983" "chlor22075" "chlor23253" "chlor23630" "chlor23632"
## [16] "chlor24382" "chlor24727" "col2003089" "col2003097" "col2004070"
## [21] "leu32019"   "leu32037"   "leu34505"   "leu34508"   "leuD6654"  
## [26] "san14877"   "san14879"   "san24565"   "san25117"   "san33267"  
## [31] "san34636"   "san34659"   "san35549"   "san72545"   "san7567"   
## [36] "sanB29435"  "sanB32637"  "sanB33280"  "sanB34636"  "sanB34659" 
## [41] "sanB34946"  "sanB43266"  "sanB50292"  "sanB50543"  "sanB51072" 
## [46] "sanB53055"  "sanB53068"  "sanB54673"  "sanB57402"  "sanB59372" 
## [51] "sanB60180"  "sanB60181"  "sanB60182"  "sanB60183"  "sanB60184" 
## [56] "saur18929"  "saur27804"  "saur36179"  "saur36283"  "saur36284" 
## [61] "saur69666"  "sordB33717" "sordB33718" "sordB33719" "sordB33720"
## [66] "sordB44198" "sordB44295" "sordB44296" "sordB51462" "tris18953" 
## [71] "tris27723"  "tris27752"  "tris27792"  "tris27793"  "tris32049" 
## [76] "tris33253"  "tris33839"  "tris33858"  "tris33864"  "tris33867" 
## [81] "tris33895"  "tris36188"  "tris6704"
pop(gena)<-popmap$pop
sample.div.80 <- stamppNeisD(gena, pop = FALSE)
#export for splitstree
#stamppPhylip(distance.mat=sample.div.80, file="~/Desktop/todi.2022/todi.80.splits.txt")

#80% completeness cutoff splitstree
knitr::include_graphics(c("/Users/devder/Desktop/todi.2022/todi.80.splitstree.png"))

#repeat for 85% cutoff
#output pairwise difference matrix for each to run splitstree
genb@ind.names<-gena@ind.names
pop(genb)<-popmap$pop
sample.div.85 <- stamppNeisD(genb, pop = FALSE)
#export for splitstree
#stamppPhylip(distance.mat=sample.div.85, file="~/Desktop/todi.2022/todi.85.splits.txt") 

#85% completeness cutoff splitstree
knitr::include_graphics(c("/Users/devder/Desktop/todi.2022/todi.85.splitstree.png"))

#repeat with removing singletons
vcfR.mac<-min_mac(vcfRa, min.mac = 2)
## 28.31% of SNPs fell below a minor allele count of 2 and were removed from the VCF

genc<-vcfR2genlight(vcfR.mac)
genc@ind.names<-gena@ind.names
pop(genc)<-popmap$pop
sample.div <- stamppNeisD(genc, pop = FALSE)
#export for splitstree
#stamppPhylip(distance.mat=sample.div, file="~/Desktop/todi.2022/todi.80.min.mac.splits.txt") 

#80% completeness cutoff with min.mac splitstree
knitr::include_graphics(c("/Users/devder/Desktop/todi.2022/todi.80.mac.splitstree.png"))

#the three splitstrees are nearly identical. I am satisfied that neither missing data nor singletons are driving patterns of sample relatedness/assignment. We will keep the 85% complete dataset without a minor allele filter for downstream analyses because it looks the cleanest.
#plot depth per snp and per sample
dp <- extract.gt(vcfRa, element = "DP", as.numeric=TRUE)
heatmap.bp(dp, rlabels = FALSE)

#plot genotype quality per snp and per sample
gq <- extract.gt(vcfRa, element = "GQ", as.numeric=TRUE)
heatmap.bp(gq, rlabels = FALSE)

###We can use the convenient function ‘write.vcf’ from vcfR to export our filtered vcf file for downstream analyses

#write out vcf
vcfR::write.vcf(vcfRb, file = "~/Desktop/todi.2022/todi.85.vcf.gz")
#perform linkage filtering to get a reduced vcf with only unlinked SNPs
vcfR.thin<-distance_thin(vcfRb, min.distance = 100)
## 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |==                                                                    |   3%
  |                                                                            
  |====                                                                  |   6%
  |                                                                            
  |=======                                                               |   9%
  |                                                                            
  |=========                                                             |  12%
  |                                                                            
  |===========                                                           |  16%
  |                                                                            
  |=============                                                         |  19%
  |                                                                            
  |===============                                                       |  22%
  |                                                                            
  |==================                                                    |  25%
  |                                                                            
  |====================                                                  |  28%
  |                                                                            
  |======================                                                |  31%
  |                                                                            
  |========================                                              |  34%
  |                                                                            
  |==========================                                            |  38%
  |                                                                            
  |============================                                          |  41%
  |                                                                            
  |===============================                                       |  44%
  |                                                                            
  |=================================                                     |  47%
  |                                                                            
  |===================================                                   |  50%
  |                                                                            
  |=====================================                                 |  53%
  |                                                                            
  |=======================================                               |  56%
  |                                                                            
  |==========================================                            |  59%
  |                                                                            
  |============================================                          |  62%
  |                                                                            
  |==============================================                        |  66%
  |                                                                            
  |================================================                      |  69%
  |                                                                            
  |==================================================                    |  72%
  |                                                                            
  |====================================================                  |  75%
  |                                                                            
  |=======================================================               |  78%
  |                                                                            
  |=========================================================             |  81%
  |                                                                            
  |===========================================================           |  84%
  |                                                                            
  |=============================================================         |  88%
  |                                                                            
  |===============================================================       |  91%
  |                                                                            
  |==================================================================    |  94%
  |                                                                            
  |====================================================================  |  97%
  |                                                                            
  |======================================================================| 100%
## 1892 out of 7430 input SNPs were not located within 100 base-pairs of another SNP and were retained despite filtering
vcfR.thin
## ***** Object of Class vcfR *****
## 83 samples
## 32 CHROMs
## 1,892 variants
## Object size: 12.1 Mb
## 8.083 percent missing data
## *****        *****         *****
vcfR::write.vcf(vcfR.thin, file = "~/Desktop/todi.2022/todi.unlinked.85.vcf.gz")